<template>
  <el-dialog
      v-model="dialogVisible"
      title="Tips"
      width="30%"
      :before-close="handleClose"
  >
    <span>确认关闭编辑页面么？</span>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="closeBtn"
        >关闭</el-button
        >
      </span>
    </template>
  </el-dialog>

  <el-drawer
      v-model="drawerStatus"
      title="文章编辑"
      direction="rtl"
      size="80%"
      :before-close="drawerClose"
  >
    <div style="height: 100%;width: 100%;">
      <el-row justify="center" style="height: 100%">
        <el-col :span="18">
          <div style="height: 60px;width: 100%;display: flex;justify-content: space-between;align-items: center">
            <div style="display: flex;align-items: center;width: 500px">
              <span style="width: 80px">标题：</span>
              <el-input size="small" v-model="editArticleTitle"></el-input>
            </div>
            <div>
              <el-select v-model="SortContent" size="small" placeholder="分类">
                <el-option
                    v-for="item in SortList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
          </div>
          <div style=";height: 80%;width: 100%;margin-top: 20px">
            <v-md-editor
                v-model="content"
                :disabled-menus="imageList"
                @upload-image="UploadImage"
                mode="edit"
                :tab-size="4"
                :autofocus="true"
                :toc-nav-position-right="true"
                @copy-code-success="handleCopyCodeSuccess"
                @save="saveBtn"
                height="600px"
            ></v-md-editor>
          </div>
        </el-col>
        <el-col :offset="2" :span="2">
          <div style="height: 60px;display: flex;align-items: center">
            <el-button size="small" type="primary" @click="updateArticleBtn">更新</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
  </el-drawer>

  <div class="articleList">
    <div>
      <el-breadcrumb>
        <el-breadcrumb-item :to="{ path: '/admin/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>文章管理</el-breadcrumb-item>
        <el-breadcrumb-item>文章仓库</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-row justify="center" style="margin-top: 30px">
      <el-col :span="18"
              style="box-shadow:rgb(205 205 205) 0 1px 23px;"
      >
        <el-table :data="ArticleContent"
                  v-loading="loading"
                  element-loading-text="Loading..."
                  style="width: 100%">
          <el-table-column type="selection" width="85"/>
          <el-table-column prop="id" label="Id" width="115"/>
          <el-table-column prop="title" label="标题"/>
          <el-table-column prop="class" label="分类"/>
          <el-table-column prop="content" label="内容"/>
          <el-table-column prop="author" label="作者"/>
          <el-table-column>
            <template #default="scope">
              <div style="display: flex;justify-content: center">
                <div>
                  <el-button size="mini" type="primary" @click="editArticleBtn(scope.$index)">编辑</el-button>
                </div>
                <div style="margin-left: 25px">
                  <el-button size="mini" type="danger" @click="deleteArticleBtn(scope.$index)">删除</el-button>
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <div style="width: 100%;margin-top: 15px;margin-bottom: 15px">
          <el-pagination background layout="prev, pager, next" :total="numTotal" @current-change="newPages">
          </el-pagination>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import ArticleStorehouse from "./ArticleStorehouse";

export default {
  name: "ArticleStorehouse",
  setup() {
    return {
      ...ArticleStorehouse()
    }
  }
}
</script>

<style scoped>
.articleList {
  height: 100%;
}
</style>